package com.familyigo.gdemo;

import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.DefineNamedBindings;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
import org.jdbi.v3.stringtemplate4.UseStringTemplateSqlLocator;

import java.util.List;

// 注册 User 类的映射器
@RegisterBeanMapper(User.class)
public interface UserDao {
    // 创建 users 表的 SQL 语句
    @SqlUpdate("CREATE TABLE IF NOT EXISTS users (" +
            "id IDENTITY PRIMARY KEY, " +
            "name VARCHAR(255), " +
            "age INT, " +
            "status VARCHAR(255)" +
            ")")
    void createTable();

    // 插入用户数据的 SQL 语句
    @SqlUpdate("INSERT INTO users (name, age, status) VALUES (:name, :age, :status)")
    void insert(@Bind("name") String name, @Bind("age") int age, @Bind("status") String status);

    // 查询所有用户数据的 SQL 语句
    @SqlQuery
    @DefineNamedBindings
    @UseStringTemplateSqlLocator
    List<User> listUsers(User user);
}